﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HZ.DrugTrade.Web
{
    public partial class UpdateGoodsInfo : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }
        public void Bind()
        {
            string goodsid = "";
            if (Request.QueryString["goodsid"] != null)
            {
                goodsid = Request.QueryString["goodsid"];
            }
            HZ.DrugTrade.Model.Goods goods = HZ.DrugTrade.BLLFactory.Factory.BLL_Goods().GetGoodsInfoByWhere(goodsid);
            lblGoodsID.Text = goods.GoodsID;
            txtGoodsname.Text = goods.GoodsName;
            txtOutlookcModel.Text = goods.Outlookc;
            txtProductMaterial.Text = goods.Material;
            txtBrand.Text = goods.Brand;
            txtStandardName.Text = goods.StandardName;
            txtStandardId.Text = goods.StandardId;
            txtCompanyName_SC.Text = goods.CompanyName_SC;
            txtMinUnit.Text = goods.Unit;
            txtQuality2.Text = goods.QualityLevel;
            txtQuality1.Text = goods.CPRZTX;
            txtRegCode.Text = goods.RegCode;
            txtRegName.Text = goods.RegName;
            txtRegDate.Text = goods.RegDate.ToString();
            txtRegisterTime.Text = goods.RegisterTime.ToString();
            txtCOMPANYADDRESS_SC.Text = goods.COMPANYADDRESS_SC;
            txtCOMPANYLOCALADDRESS_SC.Text = goods.COMPANYLOCALADDRESS_SC;
            txtProApplication.Text = goods.ProApplication;
            txtPerformance.Text = goods.Performance;
            if (!string.IsNullOrEmpty(goods.picurl))
            {
                string strUrl = goods.picurl.Replace("&nbsp;&nbsp;", "$");
                string[] url = strUrl.Split(new char[] { '$' });
                string Strhtml = "";

                foreach (string s in url)
                {

                    if (s.Trim() != "")
                        Strhtml += "&nbsp;&nbsp;" + s;
                }
                this.div_pic.InnerHtml = Strhtml;
            }
        }
        int i = 0;
        protected void btnUnPass_Click(object sender, EventArgs e)
        {
            if (ViewState["i"] != null && ViewState["i"].ToString() != "")
            {
                i = (int)ViewState["i"] + 1;
                ViewState["i"] = i;
            }
            else
            {
                i++;
                ViewState["i"] = i;
            }
            HZ.DrugTrade.Model.Goods goods = new Model.Goods();
            goods.GoodsID = lblGoodsID.Text.Trim();
            goods.GoodsName = txtGoodsname.Text.Trim();
            goods.Outlookc = txtOutlookcModel.Text.Trim();
            goods.Material = txtProductMaterial.Text.Trim();
            goods.Brand = txtBrand.Text.Trim();
            goods.StandardName = txtStandardName.Text.Trim();
            goods.StandardId = txtStandardId.Text.Trim();
            goods.CompanyName_SC = txtCompanyName_SC.Text.Trim();
            goods.Unit = txtMinUnit.Text.Trim();
            goods.QualityLevel = txtQuality2.Text.Trim();
            goods.CPRZTX = txtQuality1.Text.Trim();
            goods.RegCode = txtRegCode.Text.Trim();
            goods.RegName =txtRegName.Text.Trim();
            goods.RegDate = new HZ.Common.ConvertHelper(txtRegDate.Text.Trim()).ToDateTime;
            goods.RegisterTime = new HZ.Common.ConvertHelper(txtRegisterTime.Text.Trim()).ToDateTime;
            goods.COMPANYADDRESS_SC = txtCOMPANYADDRESS_SC.Text.Trim();
            goods.COMPANYLOCALADDRESS_SC = txtCOMPANYLOCALADDRESS_SC.Text.Trim();
            goods.ProApplication = txtProApplication.Text.Trim();
            goods.Performance = txtPerformance.Text.Trim();
            int state = HZ.DrugTrade.BLLFactory.Factory.BLL_Goods().UpdateGoodsInfo(goods);
            if (state == 1)
            {
                //PageError("修改成功！", "");
                Page.RegisterStartupScript("", "<script> alert('修改成功！')</script>");
            }
            else
            {
                //PageError("修改失败！", "");
                Page.RegisterStartupScript("", "<script> alert('修改失败！')</script>");
            }
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            if (ViewState["i"] != null && ViewState["i"].ToString() != "")
            {
                int count = 2 + (int)ViewState["i"];
                this.RegisterClientScriptBlock("e", "<script language=javascript>history.go(-" + count + ");</script>");
            }
            else
            {
                this.RegisterClientScriptBlock("e", "<script language=javascript>history.go(-2);</script>");
            }
        }
    }
}